<template>
	<el-container v-if="isAlready" ref="mainBody">
	  <el-header>
		<div class="left-panel">
		  <fsButton ref="button" plain size="default" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
		</div>
		<div class="right-panel">
			<ex-search ref="search" :searches="searches" @searchOk="searchHandler" default-code="code" placeholder="请输入资产编码" :fixedParam="fixedParams" :initParams="searchParams">
			</ex-search>
		</div>
	  </el-header>
	  <el-main class="nopadding">
		<el-container>
		  <el-main class="nopadding" style="overflow: hidden;">
			<ex-table id="hsAssetTable" ref="table" :columns="columns" :url="this.$API.asset.asset.pageDataForHsHouse.url" :refs="this.$refs" search="search" :headerRow="headerRow" :params="{}" @columnClick="columnClickHandler"></ex-table>
		  </el-main>
		</el-container>
	  </el-main>
	</el-container>

  <data-card ref="dataCard"></data-card>

  </template>

  <script>
  import ExTable from "@/components/exTable/index.vue";
  import ExSearch from "@/components/exSearch/index.vue";
  import ExTreeNavigation from "@/components/exSearchTree/index.vue";
  import ExSearchTree from "@/components/exSearchTree/index.vue";
  import DataCard from "@/views/asset/card/card.vue";
  import formRule from "@/utils/formRule";
  import useTabs from "@/utils/useTabs";
  import constant from "@/constant";
  import BaseTemplate from "@/utils/baseTemplate";
  //import dict from "@/utils/dict";

  export default {
	components: {
    DataCard,
	  ExSearchTree,
	  ExTreeNavigation,
	  ExSearch,
	  ExTable,
	},
	data() {
	  return {
		dialog: {
		  save: false,
		  permission: false
		},
		apiObj: [],
		buttons: [
        	{name: this.$t('button.export'), icon: "el-icon-download", type: "info", click: "export", permission: ""},
		],
		searches: [
		  {type: "input", name: "房产编码", code: "code", placeholder: "请输入房产编码"},
		  {type: "input", name: "房产名称", code: "name", placeholder: "请输入房产名称",},
		  {type: "input", name: "财务编码", code: "financialCode", placeholder: "请输入财务编码"},
		  {type: "input", name: "城市", code: "cityName", placeholder: "请输入城市"},
		  {type: "input", name: "地址", code: "address", placeholder: "请输入地址"},
		  {type: "select", name: "是否相同", code: "isSame",  placeholder: "请选择是否相同", dictCode:'HS_HOUSE_IS_SAME'},
		],
		columns: [
			{code: "code", name: "华士房产编码", width:"150"},
			{code: "assetName", name: "房产名称", width:"200"},
			{code: "financialCode", name: "财务编码", width:"180"},
			{code: "cityName", name: "城市", width:"120"},
			{code: "address", name: "地址", width:"200"},
			{code: "isSame", name: "是否相同", width:"100", formatter:"DICT",key: "HS_HOUSE_IS_SAME"},
		  	// {code: "assetInfo.code", name: "固资编码", width:"150",click:"show1"},
			// {code: "assetInfo.name", name: "固资名称", width:"200"},
		  	// {code: "assetInfo.financialCode", name: "固资财务编码", width:"180"},
		  	// {code: "assetInfo.other.city", name: "固资城市", width:"160"},
		  	// {code: "assetInfo.other.address", name: "固资地址", width:"160"},
			// {code: "assetInfo.storePlaceId", name: "资产位置",width: "120", formatter:"DICT",key: "FamsPosition"},
			// {code: "assetInfo.mainCategoryCode", name: "资产大类",width:"150", formatter:"DICT",key: "FamsAssetCategory"},
			// {code: "assetInfo.assetCategoryId", name: "资产分类",width:"150", formatter:"DICT",key: "FamsAssetCategory"},
			// {code: "assetInfo.assetStatusId", name: "资产状态", width:"75",formatter:"DICT",key: "ASSET_STATUS"},
			// {code: "assetInfo.other.inDocumentCode", name: "入库单号", width:"120"},
			// {code: "assetInfo.createUser", name: "入库人", width:"80",formatter: "DICT",key: "SysUser"},
			// {code: "assetInfo.createTime", name: "入库日期", width:"165",formatter: "DATETIME"},
		],
		parentLevelCode:"",
    	assetIds:[],
	    isAlready:false,
		fixedParams:{},
		searchParams:{},
		cardName: '',
		tempParams:{},
		headerRow:false,
		headerArray:[],
	  }
	},
	async created() {
		try {
			if (this.$route.meta.relTemplateId) {
				//读取卡片信息
				let card = await this.$cache.data.loadDataCard(this.$route.meta.relTemplateId);
				if (card) {
					this.cardName = card.name;
					let columns = card.modules[0].widgets[0].props.columns;
					if (columns) {
						columns.forEach(column => {
							formRule.updateColumnFormatter(column);
							column.property = 'assetInfo.'+ column.property;
							this.columns.push(column);
						});
					}
				} else {
					this.$message.error(this.$t('common.config_error'));
					useTabs.close();
				}
			}
			this.isAlready = true;
		} catch (err) {
			this.$message.error(this.$t('common.config_error'));
			useTabs.close();
			console.log(err);
		}
	},
	async mounted() {

	},
	  methods: {
	  buttonHandler(index, name) {
		this.$options.methods[name](this, index);
	  },
	  async searchTreeHandler(data) {
		let queryParams = {pathCode:data.levelCode}
		this.parentLevelCode= data.levelCode;
		await this.$refs.table.refresh(queryParams);
	  },

	  async searchHandler() {
		  this.tempParams.pathCode=this.parentLevelCode;
		  await this.$refs.table.refresh(this.tempParams);
	  },
	  columnClickHandler(name,data){
		this.$options.methods[name](this, data);
	  },
	//查看
	async show1(_this, row) {
    let assetCategory = await _this.$cache.data.loadAssetCategory(row.assetInfo.assetCategoryId);
    try {
      _this.loading = true;
      let entity = {cardId: assetCategory.assetCardId, _editFlag: false}
      _this.$nextTick(() => {
        _this.cardPreview = false;
        _this.$refs.dataCard.open(Object.assign(entity, row.assetInfo));
      });
    } finally {
      _this.loading = false;
    }
  },
    //导出
    async export(_this,index) {
      let attachParams = {};
      attachParams.exportType = 'hsHouseAsset';

      let exportApi = _this.$API.asset.asset.export;
      let exTableRef = _this.$refs.table;
      let exportBtnRef = _this.$refs.button;
      await BaseTemplate.export(_this, exportApi, attachParams, exportBtnRef, index, exTableRef);
    },

	}
  }

  </script>
  <style>
.headerRow{
	width:100%;

  }
  .headerRow .headerCol{
	overflow-wrap: break-word;
    color: #fff;
	text-align: left;
	border:1px #edf2f7 solid;
	font-size: 14px;
    font-family: PingFangSC-Semibold;
    font-weight: 400;
	color: #666666;
	padding-bottom: 10px;

  }

  .headerRow .headerCol .statusname{
	margin-top: 10px;
    white-space: nowrap;
	margin-bottom: 10px;
	font-size: 17px;
	font-weight: 530;
	color: rgb(45, 55, 72);

  }
  .headerRow .headerCol .countname{
	font-size: 18px;
	margin-bottom: 6px;
	font-weight: 0;
	color: rgb(45, 55, 72);
  }
  .headerRow .headerCol span{
	color: #666666;
  }

  .searchcheckbox .el-checkbox__label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
</style>
